A short description of the post.
# Read in the oil spill data and CA shapefiles
ca_oil <- read_sf(here("data", "ds394"), layer = "ds394") %>%
clean_names()
# st_crs(ca_oil)
ca_counties <- read_sf(here("data", "ca_counties"), layer = "CA_Counties_TIGER2016") %>%
clean_names() %>%
select(name)
# st_crs(ca_counties)
# Make exploratoy map to show where the CA oil spills have been
ggplot() +
geom_sf(data = ca_counties, fill = "wheat") +
geom_sf(data = ca_oil,
color = "deepskyblue4",
alpha = 0.3,
size = 1.2) +
theme_minimal() +
labs(x = "Latitude",y = "Longitude", title = "Oil Spill Incidents in California")

Figure 1: Each point on this map of California represents a specific oil spill incident from 2008 (Data: CA DFW Oil Spill Incident Tracking, 2008)."
tmap_mode("view")
tm_basemap("Esri.WorldTopoMap") +
tm_shape(ca_oil) +
tm_dots(aes(color = "cyan4"))
Figure 2: This interactive map allows viewers to zoom in on specific regions of California to more precisely see where these oil spill incidents occured in 2008 (CA DFW Oil Spill Incident Tracking, 2008).
# Make new subset
ca_oil_subset <- ca_oil %>%
select(localecoun, geometry) %>%
rename(name = localecoun)
# Join together
ca_oil_inland <- ca_counties %>%
st_join(ca_oil_subset)
# Get counts of inland oil spill events
oil_counts <- ca_oil_inland %>%
count(name.x)
# Make a chloropleth map in ggplot
# fill color depends on count of inland oil spill events by county
ggplot(data = oil_counts) +
geom_sf(aes(fill = n), color = "black", size = 0.1) +
scale_fill_gradientn(colors = c("lightsteelblue", "royalblue", "navy")) +
theme_minimal() +
labs(x = "Latitude", y = "Longitude", title = "Chloropleth Map of Oil Spill Incidents in 2008", fill = "Oil Spill Incidents")

Figure 3: The chloropleth map of California reveals which counties had the most oil spill incidents in 2008. The darkest counties are those that experienced the greatest number of incidents and the lightest are those that experienced the least (Data: CA DFW Oil Spill Incident Tracking, 2008).